import { TMountReincarnate } from "../../../Message/Db/Tables/TMountReincarnate";
import { TMountModelMark } from "../../../Message/Db/Tables/TMountModelMark";
import { TModelEffectDt } from "../../../Message/Db/Tables/TModelEffectDt";
import { DateParser } from "../../common/tools/DateParser";
import { MountUpdateInfo } from "./info/MountUpdateInfo";
import { MountExpInfo } from "./info/MountExpInfo";
import { ItemData } from "./info/ItemData";
import { Cache } from "../cache/Cache";
import { ClockManager } from "../manager/ClockManager";
import { ConfigManager } from "../../../com/gengine/resource/ConfigManager";
import { TMountEquipUpgrade } from "../../../Message/Db/Tables/TMountEquipUpgrade";
import { TMountAdvanceCost } from "../../../Message/Db/Tables/TMountAdvanceCost";
import { TMountAdvance } from "../../../Message/Db/Tables/TMountAdvance";
import { TMountStars } from "../../../Message/Db/Tables/TMountStars";
import { TMountStarsAttribute } from "../../../Message/Db/Tables/TMountStarsAttribute";
import { CutDataUtil } from "../../common/tools/CutDataUtil";
import { EJewel } from "../../../Message/Public/EJewel";
import { CareerUtil } from "../view/common/util/CareerUtil";
type int = number;
//class MountConfig
    
    export  class MountConfig
    {
        constructor()
        {
            
            this._mapUpdate = new Map<any, any> /* flash.utils.Dictionary */();
            this._mapExp = new Map<any, any> /* flash.utils.Dictionary */();
            this._mapModelEffectDt = new Map<any, any> /* flash.utils.Dictionary */();
            this._arrDt = [];
            this._mapMark = new Map<any, any> /* flash.utils.Dictionary */();
            this._mapRein = new Map<any, any> /* flash.utils.Dictionary */();
            this._mapStarts = new Map<any, any> /* flash.utils.Dictionary */();
            this.mapStartsArr = [];
            this._mapStartsAttribute = new Map<any, any> /* flash.utils.Dictionary */();
            this._mapStartsFactor = new Map<any, any> /* flash.utils.Dictionary */();
            this._mapAdDic = new Map<any, any> /* flash.utils.Dictionary */();
            this._meStarDic = new Map<any, any> /* flash.utils.Dictionary */();
            this._meHighestColorDic = new Map<any, any> /* flash.utils.Dictionary */();
            this._meDic = new Map<any, any> /* flash.utils.Dictionary */();
            this._mapAdCostDic = new Map<any, any> /* flash.utils.Dictionary */();
            if (MountConfig._instance != null) 
            {
                throw new Error(" MountConfig 单例 ");
            }
            this.init();
            return;
        }

        /* internal  */writeRein(arg1: Object): void
        {
            var loc2=null;
            var loc3=null;
            var loc1=[];
            var loc4=0;
            var loc5=arg1;
            for(loc3 of loc5) 
            {
                loc2 = new TMountReincarnate();
                loc2.type = loc3.type;
                loc2.code = loc3.code;
                loc2.amount = loc3.amount;
                loc2.uint = loc3.uint;
                loc2.cost = loc3.cost;
                loc2.attributeAdd = loc3.attributeAdd;
                this._mapRein[loc2.type] = loc2;
                loc1.push(loc2);
            }
            this._reinNum = loc1.length;
            return;
        }

        /* internal  */writeMark(arg1: Object): void
        {
            var loc1=null;
            var loc2=null;
            var loc3=0;
            var loc4=arg1;
            for(loc2 of loc4) 
            {
                loc1 = new TMountModelMark();
                loc1.modelId = loc2.modelId;
                loc1.sexLimit = loc2.sexLimit;
                loc1.canMark = loc2.canMark;
                loc1.oppositeSexModelId = loc2.oppositeSexModelId;
                this._mapMark[loc1.modelId] = loc1;
            }
            return;
        }

        public getMountMarkInfo(arg1: string): TMountModelMark
        {
            if (this._mapMark[arg1]) 
            {
                return this._mapMark[arg1];
            }
            return null;
        }

        /* internal  */writeDt(arg1: Object): void
        {
            var loc1=null;
            var loc2=null;
            if (arg1 === null) 
            {
                this._isNull = true;
            }
            else 
            {
                this._isNull = false;
                var loc3=0;
                var loc4=arg1;
                for(loc2 of loc4) 
                {
                    loc1 = new TModelEffectDt();
                    loc1.modelId = loc2.modelId;
                    loc1.effectDt = DateParser.strToDateNormal(loc2.effectDt);
                    this._mapModelEffectDt[loc1.modelId] = loc1;
                    this._arrDt.push(loc1.modelId);
                }
            }
            return;
        }

        /* internal  */writeUpdate(arg1: Object): void
        {
            var loc1=null;
            var loc2=null;
            var loc3=0;
            var loc4=arg1;
            for(loc2 of loc4) 
            {
                loc1 = new MountUpdateInfo();
                loc1.id = loc2.id;
                loc1.level = loc2.level;
                loc1.nibus = loc2.nibus;
                loc1.rate = loc2.rate;
                loc1.materialNum = loc2.materialNum;
                loc1.cost = loc2.cost;
                this._mapUpdate[loc1.id] = loc1;
            }
            return;
        }

        /* internal  */writeExp(arg1: Object): void
        {
            var loc1=null;
            var loc2=null;
            var loc3=0;
            var loc4=arg1;
            for(loc2 of loc4) 
            {
                loc1 = new MountExpInfo();
                loc1.expPerDegree = loc2.expPerDegree;
                loc1.upgradeNeedExperience = loc2.upgradeNeedExperience;
                loc1.level = loc2.level;
                this._mapExp[loc1.level] = loc1;
            }
            return;
        }

        public MountConfig.get arrDt(): Array<any>
        {
            return this._arrDt;
        }

        public getFashionWeaponEffect(arg1: string): TModelEffectDt
        {
            return this._mapModelEffectDt[arg1];
        }

        public getTotalExpByLevel(arg1: int): number
        {
            if (this._mapExp) 
            {
                if (this._mapExp[arg1]) 
                {
                    return this._mapExp[arg1].upgradeNeedExperience;
                }
            }
            return 0;
        }

        public getExpPerDegree(arg1: int): int
        {
            var loc1=0;
            if (this._mapExp[arg1]) 
            {
                loc1 = this._mapExp[arg1].expPerDegree;
            }
            return loc1;
        }

        public getUpdateItem(arg1: int): MountUpdateInfo
        {
            var loc1=null;
            loc1 = this._mapUpdate[arg1];
            return loc1;
        }

        public getTotalStrengthen(): int
        {
            var loc1=null;
            var loc2=null;
            var loc3=0;
            var loc4=0;
            var loc5=0;
            if (this._totleStrengthen != 0) 
            {
                return this._totleStrengthen;
            }
            var loc6=0;
            var loc7=this._mapUpdate;
            for(loc1 of loc7) 
            {
                loc3 = 0;
                loc2 = loc1.rate.split("#");
                loc5 = 0;
                while (loc5 < loc2.length) 
                {
                    loc4 = parseInt((loc2[loc5] as string).split(",")[0]);
                    loc3 = Math.max(loc3, loc4);
                    ++loc5;
                }
                this._totleStrengthen = this._totleStrengthen + loc3;
            }
            return this._totleStrengthen;
        }

        public MountConfig.get reinNum(): int
        {
            return this._reinNum;
        }

        public checkModelDt(arg1: string, arg2: ItemData): Boolean
        {
            var loc2=false;
            var loc3=NaN;
            var loc4=false;
            var loc5=NaN;
            var loc6=null;
            var loc7=null;
            var loc8=null;
            var loc9=0;
            var loc10=0;
            if (this._isNull && !Cache.instance.pack.mountsPackCache.isTimeliness(arg2)) 
            {
                return true;
            }
            if (this.arrDt.indexOf(arg1) == -1 && !Cache.instance.pack.mountsPackCache.ModelIsTimeliness(arg1, arg2)) 
            {
                return true;
            }
            var loc1=ClockManager.instance.nowDate;
            if (arg2 && arg2.itemExInfo) 
            {
                loc7 = arg2.itemExInfo.m_effect_dt;
                loc8 = [];
                loc9 = 0;
                while (loc9 < loc7.length) 
                {
                    if ((loc8 = loc7[loc9])[0] == arg1) 
                    {
                        loc3 = loc8[1] * 24 * 3600 * 1000;
                        loc2 = true;
                    }
                    ++loc9;
                }
            }
            if (this._arrDt.length > 0) 
            {
                loc10 = 0;
                while (loc10 < this.arrDt.length) 
                {
                    if (arg1 == this.arrDt[loc10]) 
                    {
                        loc5 = (loc6 = (this._mapModelEffectDt[arg1] as TModelEffectDt).effectDt).getTime();
                        loc4 = true;
                    }
                    ++loc10;
                }
            }
            if (loc4 && loc2) 
            {
                if (loc1.getTime() < loc3 || loc1.getTime() < loc5) 
                {
                    return true;
                }
                return false;
            }
            if (!loc4 && !loc2) 
            {
                return true;
            }
            if (loc4) 
            {
                if (loc1.getTime() < loc5) 
                {
                    return true;
                }
                return false;
            }
            if (loc2) 
            {
                if (loc1.getTime() < loc3) 
                {
                    return true;
                }
                return false;
            }
            return false;
        }

        public MountConfig.get mapModelEffectDt(): Map<any, any> /* flash.utils.Dictionary */
        {
            return this._mapModelEffectDt;
        }

        public init(): void
        {
            var loc1=ConfigManager.instance.getJSONByFileName("t_mount_update.json");
            this.writeUpdate(loc1);
            var loc2=ConfigManager.instance.getJSONByFileName("t_mount_experience.json");
            this.writeExp(loc2);
            var loc3=ConfigManager.instance.getJSONByFileName("t_model_effect_dt.json");
            this.writeDt(loc3);
            var loc4=ConfigManager.instance.getJSONByFileName("t_mount_model_mark.json");
            this.writeMark(loc4);
            var loc5=ConfigManager.instance.getJSONByFileName("t_mount_reincarnate.json");
            this.writeRein(loc5);
            var loc6=ConfigManager.instance.getJSONByFileName("t_mount_stars.json");
            this.writeMS(loc6);
            var loc7=ConfigManager.instance.getJSONByFileName("t_mount_stars_attribute.json");
            this.writeMSA(loc7);
            var loc8=ConfigManager.instance.getJSONByFileName("t_mount_advance.json");
            this.writeMAD(loc8);
            var loc9=ConfigManager.instance.getJSONByFileName("t_mount_advance_cost.json");
            this.writeMADC(loc9);
            var loc10=ConfigManager.instance.getJSONByFileName("t_mount_equip_upgrade.json");
            this.writeMEU(loc10);
            return;
        }

        public getDt(arg1: string, arg2: ItemData): string
        {
            var loc2=false;
            var loc3=NaN;
            var loc4=false;
            var loc5=NaN;
            var loc6=null;
            var loc7=null;
            var loc8=null;
            var loc9=null;
            var loc10=0;
            var loc11=0;
            if (this._isNull && !Cache.instance.pack.mountsPackCache.isTimeliness(arg2)) 
            {
                return "";
            }
            if (this.arrDt.indexOf(arg1) == -1 && !Cache.instance.pack.mountsPackCache.ModelIsTimeliness(arg1, arg2)) 
            {
                return "";
            }
            var loc1=ClockManager.instance.nowDate;
            if (arg2 && arg2.itemExInfo) 
            {
                loc8 = arg2.itemExInfo.m_effect_dt;
                loc9 = [];
                loc10 = 0;
                while (loc10 < loc8.length) 
                {
                    if ((loc9 = loc8[loc10])[0] == arg1) 
                    {
                        loc3 = loc9[1] * 24 * 3600 * 1000;
                        loc2 = true;
                    }
                    ++loc10;
                }
            }
            if (this._arrDt.length > 0) 
            {
                loc11 = 0;
                while (loc11 < this.arrDt.length) 
                {
                    if (arg1 == this.arrDt[loc11]) 
                    {
                        loc5 = (loc6 = (this._mapModelEffectDt[arg1] as TModelEffectDt).effectDt).getTime();
                        loc4 = true;
                    }
                    ++loc11;
                }
            }
            if (loc4 && loc2) 
            {
                if (loc1.getTime() < loc3 || loc1.getTime() < loc5) 
                {
                    return (loc7 = new Date(Math.max(loc3, loc5))).getFullYear() + "," + (loc7.getMonth() + 1) + "," + loc7.getDate();
                }
                return "";
            }
            if (!loc4 && !loc2) 
            {
                return "";
            }
            if (loc4) 
            {
                if (loc1.getTime() < loc5) 
                {
                    return (loc7 = new Date(loc5)).getFullYear() + "," + (loc7.getMonth() + 1) + "," + loc7.getDate();
                }
                return "";
            }
            if (loc2) 
            {
                if (loc1.getTime() < loc3) 
                {
                    return (loc7 = new Date(loc3)).getFullYear() + "," + (loc7.getMonth() + 1) + "," + loc7.getDate();
                }
                return "";
            }
            return "";
        }

        public isDtModel(arg1: string): Boolean
        {
            var loc1=false;
            var loc2=0;
            if (this._arrDt.length > 0) 
            {
                loc2 = 0;
                while (loc2 < this._arrDt.length) 
                {
                    if (arg1 == this._arrDt[loc2]) 
                    {
                        loc1 = true;
                        break;
                    }
                    ++loc2;
                }
                if (loc1) 
                {
                    return true;
                }
                return false;
            }
            return false;
        }

        public isCanCrave(arg1: ItemData): Boolean
        {
            var loc1=false;
            var loc2=null;
            if (arg1.itemExInfo && arg1.itemExInfo.model_id) 
            {
                if (this._mapMark[arg1.itemExInfo.model_id] == null) 
                {
                    loc1 = false;
                }
                else 
                {
                    loc2 = this._mapMark[arg1.itemExInfo.model_id];
                    if (loc2.canMark != 1) 
                    {
                        loc1 = false;
                    }
                    else 
                    {
                        loc1 = true;
                    }
                }
            }
            return loc1;
        }

        /* internal  */writeMEU(arg1: Object): void
        {
            var loc1=null;
            var loc2=null;
            var loc3=null;
            var loc4=0;
            var loc5=0;
            var loc6=0;
            var loc7=arg1;
            for(loc2 of loc7) 
            {
                loc1 = new TMountEquipUpgrade();
                loc1.id = loc2.id;
                loc1.oper = loc2.oper;
                loc1.type = loc2.type;
                loc1.color = loc2.color;
                loc1.materialColor = loc2.materialColor;
                loc1.materialAmount = loc2.materialAmount;
                loc1.star = loc2.star;
                loc1.attribute = loc2.attribute;
                loc1.cost = loc2.cost;
                loc1.reverse = loc2.reverse;
                loc3 = loc1.type + "_" + loc1.color + "_" + loc1.star;
                this._meDic[loc3] = loc1;
                loc3 = loc1.type + "_" + loc1.color;
                if (this._meStarDic[loc3]) 
                {
                    if (loc1.star > this._meStarDic[loc3]) 
                    {
                        this._meStarDic[loc3] = loc1.star;
                    }
                }
                else 
                {
                    this._meStarDic[loc3] = loc1.star;
                }
                loc3 = loc1.type.toString();
                if (!this._meHighestColorDic[loc3]) 
                {
                    this._meHighestColorDic[loc3] = loc1.color;
                    continue;
                }
                if (!(loc1.color > this._meHighestColorDic[loc3])) 
                {
                    continue;
                }
                this._meHighestColorDic[loc3] = loc1.color;
            }
            return;
        }

        public isMountEquipFullStat(arg1: int, arg2: int, arg3: int): Boolean
        {
            var loc1=arg1 + "_" + arg2;
            if (this._meHighestColorDic[arg1.toString()] <= arg2 && this._meStarDic[loc1] <= arg3) 
            {
                return true;
            }
            return false;
        }

        public getMountEquipHightestColorEachType(arg1: int): int
        {
            var loc1=arg1.toString();
            var loc2=this._meHighestColorDic[loc1];
            if (loc2 && loc2 >= 0) 
            {
                return loc2;
            }
            return 0;
        }

        public getMountEquipStarByTypeColor(arg1: int, arg2: int): int
        {
            var loc1=arg1 + "_" + arg2;
            var loc2;
            if ((loc2 = this._meStarDic[loc1]) && loc2 >= 0) 
            {
                return loc2;
            }
            return 0;
        }

        public getMountEquipUpgradeInfo(arg1: int, arg2: int, arg3: int): TMountEquipUpgrade
        {
            var loc1="";
            loc1 = arg1 + "_" + arg2 + "_" + arg3;
            var loc2;
            if (loc2 = this._meDic[loc1]) 
            {
                return loc2;
            }
            return null;
        }

        public getSexLimit(arg1: string): int
        {
            var loc1=null;
            if (this._mapMark[arg1] != null) 
            {
                loc1 = this._mapMark[arg1];
                return loc1.sexLimit;
            }
            return 3;
        }

        public getRein(arg1: int): TMountReincarnate
        {
            var loc1=null;
            loc1 = this._mapRein[arg1];
            return loc1;
        }

        public static get instance(): MountConfig
        {
            if (MountConfig._instance == null) 
            {
                MountConfig._instance = new MountConfig();
            }
            return MountConfig._instance;
        }

        /* internal  */writeMADC(arg1: Object): void
        {
            var loc1=null;
            var loc2=null;
            var loc3=0;
            var loc4=arg1;
            for(loc2 of loc4) 
            {
                loc1 = new TMountAdvanceCost();
                loc1.times = loc2.times;
                loc1.cost = loc2.cost;
                this._mapAdCostDic[loc1.times] = loc1.cost;
                var loc5;
                var loc6=((loc5 = this).timeLim + 1);
                loc5.timeLim = loc6;
                if (loc1.cost != 0) 
                {
                    continue;
                }
                loc6 = ((loc5 = this).freeTime + 1);
                loc5.freeTime = loc6;
            }
            return;
        }

        public getMountAdvanceCost(arg1: int): int
        {
            if (arg1 >= this.timeLim) 
            {
                return this._mapAdCostDic[this.timeLim];
            }
            return this._mapAdCostDic[arg1];
        }

        /* internal  */writeMAD(arg1: Object): void
        {
            var loc1=null;
            var loc2=null;
            var loc3=0;
            var loc4=arg1;
            for(loc2 of loc4) 
            {
                loc1 = new TMountAdvance();
                loc1.level = loc2.level;
                loc1.value = loc2.value;
                loc1.experience = loc2.experience;
                this._mapAdDic[loc1.level] = loc1;
            }
            return;
        }

        public getAdData(arg1: int): TMountAdvance
        {
            if (this._mapAdDic[arg1]) 
            {
                return this._mapAdDic[arg1];
            }
            return new TMountAdvance();
        }

        public getMountStarts(arg1: int): TMountStars
        {
            if (this._mapStarts[arg1]) 
            {
                return this._mapStarts[arg1];
            }
            return null;
        }

        /* internal  */writeMS(arg1: Object): void
        {
            var loc1=null;
            var loc2=null;
            var loc3=0;
            var loc4=arg1;
            for(loc2 of loc4) 
            {
                loc1 = new TMountStars();
                loc1.attribute = loc2.attribute;
                loc1.cost = loc2.cost;
                loc1.level = loc2.level;
                loc1.name = loc2.name;
                loc1.propAmount = loc2.propAmount;
                loc1.propCode = loc2.propCode;
                loc1.starAmount = loc2.starAmount;
                loc1.openLevel = loc2.openLevel;
                this._mapStarts[loc1.level] = loc1;
                this.mapStartsArr.push(loc1);
            }
            return;
        }

        /* internal  */writeMSA(arg1: Object): void
        {
            var loc1=null;
            var loc2=null;
            var loc5=0;
            var loc8=null;
            var loc9=0;
            var loc3="";
            var loc4="";
            var loc6="";
            var loc7=[];
            var loc10=0;
            var loc11=arg1;
            for(loc2 of loc11) 
            {
                loc1 = new TMountStarsAttribute();
                loc1.attributeValue = loc2.attributeValue;
                loc1.color = loc2.color;
                loc1.level = loc2.level;
                loc1.addFactor = loc2.addFactor;
                loc8 = CutDataUtil.getStringWithoutSharp(loc1.attributeValue);
                loc9 = 0;
                while (loc9 < loc8.length) 
                {
                    loc3 = "";
                    loc5 = (loc7 = (loc6 = loc8[loc9]).split(","))[0];
                    loc3 = loc3 + (loc1.level.toString() + "_" + loc1.color.toString() + "_" + loc5);
                    this._mapStartsAttribute[loc3] = loc7[1];
                    ++loc9;
                }
                loc4 = loc1.level.toString() + "_" + loc1.color.toString();
                var loc12;
                loc1.addFactor = loc12 = loc2.addFactor;
                this._mapStartsFactor[loc4] = loc12;
            }
            return;
        }

        public getLvColor2Factor(arg1: string): int
        {
            var loc1=0;
            if (this._mapStartsFactor[arg1]) 
            {
                loc1 = this._mapStartsFactor[arg1];
            }
            return loc1;
        }

        public getLvColorAtt2Value(arg1: string): string
        {
            var loc1="";
            if (this._mapStartsAttribute[arg1]) 
            {
                loc1 = this._mapStartsAttribute[arg1];
            }
            return loc1;
        }

        /* internal  */fixCareerAttri(arg1: string): Array<any>
        {
            var loc4=0;
            var loc1=Cache.instance.role.careerBasic;
            var loc2=CutDataUtil.getStringWithoutSharp(arg1);
            var loc3=[];
            var loc5="";
            var loc6=[];
            var loc7=0;
            while (loc7 < loc2.length) 
            {
                if ((loc4 = (loc6 = (loc5 = loc2[loc7]).split(","))[0]) == EJewel._EJewelPhysicalAttack || loc4 == EJewel._EJewelPhysicalCrit) 
                {
                    if (CareerUtil.isPhysicalCareer(loc1)) 
                    {
                        loc3.push(loc5);
                    }
                }
                else if (loc4 == EJewel._EJewelMagicAttack || loc4 == EJewel._EJewelMagicCrit) 
                {
                    if (CareerUtil.isMagicCareer(loc1)) 
                    {
                        loc3.push(loc5);
                    }
                }
                else 
                {
                    loc3.push(loc5);
                }
                ++loc7;
            }
            return loc3;
        }

        /* internal */ /* var */_mapUpdate: Map<any, any> /* flash.utils.Dictionary */;

        /* internal */ /* var */_mapExp: Map<any, any> /* flash.utils.Dictionary */;

        /* internal */ /* var */_mapModelEffectDt: Map<any, any> /* flash.utils.Dictionary */;

        /* internal */ /* var */_arrDt: Array<any>;

        /* internal */ /* var */_isNull: Boolean;

        /* internal */ /* var */_mapMark: Map<any, any> /* flash.utils.Dictionary */;

        /* internal */ /* var */_mapStarts: Map<any, any> /* flash.utils.Dictionary */;

        public /* var */mapStartsArr: Array<any>;

        /* internal */ /* var */_mapStartsAttribute: Map<any, any> /* flash.utils.Dictionary */;

        /* internal */ /* var */_mapStartsFactor: Map<any, any> /* flash.utils.Dictionary */;

        /* internal */ /* var */_mapAdDic: Map<any, any> /* flash.utils.Dictionary */;

        /* internal */ /* var */_mapRein: Map<any, any> /* flash.utils.Dictionary */;

        /* internal */ /* var */_meStarDic: Map<any, any> /* flash.utils.Dictionary */;

        /* internal */ /* var */_meHighestColorDic: Map<any, any> /* flash.utils.Dictionary */;

        /* internal */ /* var */_meDic: Map<any, any> /* flash.utils.Dictionary */;

        /* internal */ /* var */timeLim: int;

        public /* var */freeTime: int;

        /* internal */ /* var */_mapAdCostDic: Map<any, any> /* flash.utils.Dictionary */;

        /* internal */ /* var */_reinNum: int;

        /* internal */ static /* var */_instance: MountConfig;

        /* internal */ /* var */_totleStrengthen: int=0;
    }
